package com.hdaccp.dingdan.controller;

import com.hdaccp.dingdan.dao.DingdanDao;
import com.hdaccp.dingdan.dao.DingdanxqDao;
import com.hdaccp.pojo.po.Dingdan;
import com.hdaccp.pojo.po.Dingdanxq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dd")
public class DingdanController {
    @Autowired
    private DingdanDao dingdanDao;
    @Autowired
    private DingdanxqDao dingdanxqDao;



    //根据id查询订单
    @RequestMapping("/getdingdan/{uid}")
    public List<Dingdan> queryDingdanBy(@PathVariable("uid") int uid){
        return dingdanDao.findByuid(uid);
    }

    //查询所有订单
    @RequestMapping("/dindanAll")
    public List<Dingdan> queryAlldingdan() {
        return dingdanDao.findAll();
    }

    //根据id查询订单
//    @RequestMapping("/deleteddid/{ddid}")
//    public List<Dingdan> queryDingdanByddid(@PathVariable("ddid") int ddid){
//        return dingdanDao.findByuid(ddid);
//    }
    @RequestMapping("/deletedingdan/{ddid}")
    public String yhsc(@PathVariable("ddid") String ddid ){
        String msg="1";
        try {
            dingdanDao.deleteById(ddid);
        } catch (Exception e) {
            msg="2";
            e.printStackTrace();
        }
        return msg;
    }

    //根据单号查询订单详情
    @RequestMapping("/selectxq/{ddid}")
    public List<Dingdanxq> selectddxqddid(@PathVariable("ddid") String ddid){
        return dingdanxqDao.findByddid(ddid);
    }


//    //根据id修改状态
//    @RequestMapping("/updatestate/{ddid}")
//    public String updatestate(@PathVariable("ddid") String ddid){
//
//    }


    //根据单号查询订单
    @RequestMapping("/selectddid/{ddid}")
    public List<Dingdan> selectddxqdid(@PathVariable("ddid") String ddid){
        return dingdanDao.findByddid(ddid);
    }


    //根据用户名模糊查询订单
    @RequestMapping("/mohushren/{shren}")
    public List<Dingdan> findByshren(@PathVariable("shren") String shren){
        return dingdanDao.findByshren(shren);
    }

}